﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace GenerateurTrajectoire
{
    public class Objectif
    {
        internal int X;
        internal int Y;
        public int XRobot;
        public int YRobot;
        public bool enAvant;
        public int index;

        public override string ToString()
        {
            return string.Format("{0} - {1}, {2}", index + 1, XRobot, YRobot);
        }

    }

    public class Trajectoire
    {
        public int id;
        public string nom;

        public List<Objectif> ojectifs;
    }

    public class Dossier
    {
        public int id;
        public string nom;
        public List<Dossier> dossiers;
        public List<Trajectoire> trajectoires;


        public void Save(string filename)
        {
            Stream stream = File.Open(filename, FileMode.Create);
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(this.GetType());

            x.Serialize(stream,this);
            stream.Close();
        }

        public static Dossier Get(string filename)
        {
            Dossier objectToSerialize = null;
            if (File.Exists(filename))
            {
                Stream stream = File.Open(filename, FileMode.Open);
                System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(Dossier));
                objectToSerialize = (Dossier)x.Deserialize(stream);
                stream.Close();
            }
            return objectToSerialize;
        }
    }
}
